(function($){
	
	$(function(){
		updateTime();
		window.setInterval(updateTime,500);
	});
		
	$('.tab-item', '#activeList').each(function (i) {
		$(this).click(function () {
			$(this).addClass('active');
			$(this).closest('li').siblings().find('.tab-item').removeClass('active');
			$(this).closest('.tab').siblings('.content').hide().eq(i).show();
		});
	});
	
	//<!-- 刷新时间 -->
	function getTimeInterval(startTime,destTime){
		var interval = destTime - startTime;
		if(interval > 0){
	
			var day = interval/1000/3600/24;
			day = Math.floor(day);
	
			var hour = (interval/1000 % (3600*24))/3600;
			hour = Math.floor(hour);
			if(hour < 10)hour = "0" + hour;
	
			var minute = (interval/1000 % 3600)/60;
			minute = Math.floor(minute);
			if(minute < 10)minute = "0" + minute;
	
			var second = (interval/1000 % 60);
			second = Math.floor(second);
			if(second < 10)second = "0" + second;
	
			var ms = (interval%1000/10);
			ms = Math.floor(ms);
			if(ms < 10)ms = "0" + ms;
	
			var result = hour +':' + minute + ':' + second;
			
			return result;
		}
	}

	function updateTime(){
		
		$('.down-time', '.active-list').each(function (i) {
			var serverTime = window.parseInt($(this).attr('serverTime'));
			var startTime = window.parseInt($(this).attr('startTime'));
			$(this).html(getTimeInterval(serverTime, startTime)).attr('serverTime', serverTime + 500);
		});
		
	}
	
})(jQuery);

